#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(libsbase, [0.7.2], [SounOS])
AC_CONFIG_SRCDIR([src/sbase.h])
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE

# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL

# Checks for libraries.
# FIXME: Replace `main' with a function in `-levbase':
AC_CHECK_LIB([evbase], [main])

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h fcntl.h locale.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_HEADER_TIME
AC_STRUCT_TM

#pthread
havepthread=no
AC_CHECK_LIB(pthread,pthread_create,havepthread=yes)
if test "$havepthread" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_PTHREAD"
    LDFLAGS="${LDFLAGS} -lpthread"
fi

#ssl
havessl=no
AC_CHECK_LIB(ssl, SSL_read, havessl=yes)
if test "$havessl" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_SSL"
    LDFLAGS="${LDFLAGS} -lssl -lcrypto"
fi
#zlib
havezlib=no
AC_CHECK_LIB(z, compress, havezlib=yes)
if test "$havezlib" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_ZLIB"
    LDFLAGS="${LDFLAGS} -lz"
fi

#bz2lib
havebz2lib=no
AC_CHECK_LIB(bz2, BZ2_bzCompress, havebz2lib=yes)
if test "$havebz2lib" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_BZ2LIB"
    LDFLAGS="${LDFLAGS} -lbz2"
fi

#semaphore
#havesemaphore=no
#AC_CHECK_LIB(c, sem_wait, havesemaphore=yes)
#if test "$havesemaphore" = "yes" ; then
#    CPPFLAGS="${CPPFLAGS} -DHAVE_SEMAPHORE"
#fi

havemmap=no
AC_CHECK_LIB(c, munmap, havemmap=yes)
if test "$havemmap" = "yes" ; then
    CPPFLAGS="${CPPFLAGS} -DHAVE_MMAP"
fi

AC_CHECK_EXTRA_OPTIONS


# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_REALLOC
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([gettimeofday inet_ntoa memset setlocale socket strchr strdup strerror])

AC_CONFIG_FILES([Makefile
                 doc/Makefile
                 src/Makefile])
AC_OUTPUT
